package com.example.jpa_demo01.controller;

import com.example.jpa_demo01.domain.User;
import com.example.jpa_demo01.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserRepository userRepository;

    @GetMapping("/get/{userId}")
    public User getUserById(@PathVariable("userId") Integer userId) {
        User user = userRepository.getById(userId);
        System.out.println("user=" + user);
        return user;
    }
}
